package poli.tidia.mobile;

import java.util.List;

import poli.tidia.mobile.model.Folder;
import poli.tidia.mobile.model.Resource;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyResourcesArrayAdapter extends ArrayAdapter<Resource> {
	private final Context context;
	private final List<Resource> values;

	public MyResourcesArrayAdapter(Context context, List<Resource> resources) {
		super(context, R.layout.resources_list_row, resources);
		this.context = context;
		this.values = resources;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.resources_list_row, parent, false);
		TextView textView = (TextView) rowView.findViewById(R.id.label);
		ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
		textView.setText(values.get(position).toString());
		Resource s = values.get(position);
		if (s instanceof Folder) {
			imageView.setImageResource(R.drawable.ic_folder);
		} else {
			imageView.setImageResource(R.drawable.ic_file);
		}

		return rowView;
	}
}
